
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing, {
    easeOutBack: function(x, t, b, c, d, s){
        if (s == undefined) 
            s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeOutBack2: function(x, t, b, c, d, s){
        if (s == undefined) 
            s = 0.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeOutBounce: function(x, t, b, c, d){
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        }
        else 
            if (t < (2 / 2.75)) {
                return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
            }
            else 
                if (t < (2.5 / 2.75)) {
                    return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
                }
                else {
                    return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
                }
    }
});

var login = {
    endNum: 0,
	i:0,
	flag:0,
    targetNum: 0,
    weiNum: 7,
    stop: false,
	changeComment:"",
	num:0,
    intervalArr: [],
    time: 600,
	flags:0,
	oldIndex:0,
	changepic:"",
    textListener: null,
    init: function(){
        $("#extra").css({
            height: "0px",
            opacity: "hide"
        })
        $(".regprotocol").jScrollPane();
        $(".jspPane").css({
            "text-align": "left"
        })
        login.reset_userinfo();
        Core.inputTips();
        login.dealNum();
        login.initEvent();
		login.locate();
		//login.listMore();
    },
	locate:function(){//定位垂直居中
		//var screenht=document.body.scrollHeight;
		var screenht=$(window).height()
		var divheight=$("#wrap").height();
		//alert(divheight)
		if(screenht<=divheight+18){
			$("#wrap").css({marginTop:"10px"})
		}
		else{var top=(screenht-divheight-18)/2+"px";
	   		$("#wrap").css({marginTop:top})
	    }
	},
    reset_userinfo: function(){
        if ($.cookie("repsw") == "true") {
            $("#repsw").attr("checked", true);
            $("#username").val($.cookie("userName"));
            $("#psw").val($.cookie("passWord"));
        }
    },
	changeimgs:function(){
		i=login.i%5;
		var left=-i*980+"px";
		$(".algorithm_out").stop(true,true).animate({left:left},1200,"easeOutBack2",function(){
			if(login.flag==0 && login.i<4){
				login.i++
			}else if(login.i==4 && login.flag==0){
				login.flag=1;
				login.i--;
			}else if(login.i>0 && login.flag==1){
				login.i--;	
			}else if(login.i==0 && login.flag==1){
				login.flag=0;
				login.i++;
				}
			});
		  $(".icon_cir li.icon_current").removeClass("icon_current")
		  $(".icon_cir li").eq(i).addClass("icon_current");
	},
    initEvent: function(){
			//忘记密码
  			$("#forgetpwd").click(function(e){
				e.preventDefault();	
				login.forgetPassWord();
			});
			$("#forget_ok").unbind().bind("click",function(){
				var emailVal = $("#forg_email").val();
				var usernameVal = $("#forg_username").val();
				if(emailVal==""){
					$.jBox.tip("请输入注册时的邮箱地址!","error");
					$("#forg_email").focus();
					return;
				}
				if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(emailVal)){
					$.jBox.tip("请输入正确的邮箱地址!","error");
					$("#forg_email").focus();
					return;
				}
				if(usernameVal==""){
					$.jBox.tip("请输入注册时的用户名!","error");
					$("#forg_username").focus();
					return;
				}
				var obj = new Core();
				var objtemp = {};
				objtemp.email=emailVal;
				objtemp.username=usernameVal;
				obj.url="";
				obj.params=objtemp;
				obj.success = function(data){
					if (data.error){
						$.jBox.tip(data.error.message, "error");
						return;
					}
					if(!data.result){
						$.jBox.tip("用户名与邮箱地址不匹配!","error");
					}
					if(data.result){
						$.jBox.tip("邮件已发送，请查收!","success");
						window.location.href = "login.html";
					}
				}
				obj.error = function(){
					$.jBox.tip("网络异常", "error");
				}
				$.jBox.tip("数据正在努力加载中……", "loading");
				Core.ajax(obj);
			})
			
			
			//图片切换
			$.each($(".icon_cir li"),function(key,items){
			  var left="";
			  $(items).click(function(){
				  clearInterval(login.changepic);
				  $(".icon_cir li.icon_current").removeClass("icon_current")
				  $(items).addClass("icon_current");
				   left=-key*980+"px";
				   $(".algorithm_out").stop(true,true).animate({left:left},1200,"easeOutBack2")
				   login.i=key;
				})
				$(items).mouseover(function(){
					clearInterval(login.changepic);
					$(".icon_cir li.hovercurrent").removeClass("hovercurrent")
					$(this).addClass("hovercurrent");
				 })
				 $(items).mouseout(function(){
					$(".icon_cir li.hovercurrent").removeClass("hovercurrent")
					login.changepic=setInterval(function(){
							login.changeimgs();
							},6200);//修改轮播时间
				 })
			})
			$(".algorithm").mouseover(function(){
				clearInterval(login.changepic);
			})
			$(".algorithm").mouseout(function(){
				clearInterval(login.changepic);
				login.changepic=setInterval(function(){
							login.changeimgs();
							},6200);//修改轮播时间
				})
		
        $(".loginform input").keydown(function(e){
            if (e.keyCode == 13) {
                $(this).blur()
                switch ($(this).attr("id")) {
                    case "username":
                        $("#psw").focus();
                        break;
                    case "psw":
                        $("#yzm").focus();
                        break;
					case "yzm":
						$("#repsw").focus();
                    case "repsw":
                        $("#logBtn").click();
                        break;
                }
                
            }
        })
		$(".regform input").keydown(function(e){
			if(e.keyCode==13){
				  switch ($(this).attr("id")) {
                    case "email":
                        $("#pasw").focus()
                        break;
                    case "pasw":
                        $("#rpsw").focus()
                        break;
                    case "rpsw":
                        $("#compname").focus()
                        break;
					case "compname":
                        $("#qq").focus()
                        break;
                    case "qq":
                        $("#phone").focus()
                        break;
                    case "phone":
					login.Registration();
						break;
                }
			 }
		})
        $(".reg a,.fun_btn").click(function(){
			login.registered();
        })
		/*$(".fun_btn").click(function(){
			var ele=$("#loginnav li:eq(4)")
			$(".navline").stop(true, false).animate({left: ele.attr("tag")}, 300, "easeOutBack");
			$("#bdbg").stop(true, false).animate({left: 0 - 170 * ele.attr("index")}, 1200, "easeOutBack2")
            $(".bdmain").stop(true, false).animate({left: 0 - 980 * ele.attr("index")}, 1200, "easeOutBack2")
           	$(".navline").attr("tag", ele.attr("tag"))
		})*/
		$("#extra a").each(function(i){
			var leftnum=i*55+176+'px';
			var speed=(i*55+176)/500;
			$(this).hover(function(){
				$(this).stop(true, true).animate({
					opacity: 1
				}, 300)
				$(".topnav").stop(true, true).animate({left:leftnum},300,"easeOutBack")
				$("#icon_" + $(this).find("span").text()).stop(true, true).fadeIn(300)
			}, function(){
				$(this).stop(true, true).animate({
					opacity: 0.4
				}, 300)
				$("#icon_" + $(this).find("span").text()).stop(true, true).fadeOut(300)
			}).css({
				opacity: 0.4
					})
			})
			/*$("#extra").mouseout(function(){
				  $(".topnav").stop(true, true).animate({left:"208px"},100,"easeOutBack")
				})*/
			$("#regbtn").click(function(e){//注册绑定
				e.preventDefault();
				login.Registration();
			})
			$("#rpsw,#qq,#phone,#email,#pasw").focus(function(){
				if($(this).hasClass("error")){
					$(this).removeClass("error");
				}
			})
			$("#pasw").blur(function(){
				var paw=$("#pasw").val();
				if(paw.length>0){
					if (paw.length < 6 || paw.length > 20) {
						$.jBox.tip("密码必须在6~20位之间", "error");
						$(this).addClass("error")
					}
				}
			})
			$("#rpsw").blur(function(){
				var paw = $("#pasw").val();
				var prepaw = $("#rpsw").val();
				if (paw != prepaw && prepaw!="") {
					$.jBox.tip("密码和确认密码不一致", "error");
					$(this).addClass("error")
				}
			})
			$("#qq").blur(function(){
				var qq=$("#qq").val();
				if(!login.validate_int(qq)&&login.validate_isnull(qq)){
					$.jBox.tip("请输入正确的qq号码！", "error");
					$(this).addClass("error")
				}
			})
			$("#phone").blur(function(){
				var ph=$("#phone").val().replace(/\s/g,"");
			    if (!login.validate_phone(ph)&&login.validate_isnull(ph)) {
						  $.jBox.tip("请输入正确的电话号码！", "error");
						  $(this).addClass("error")
				}
			})
			$("#email").blur(function(){
				var email=$("#email").val();
				  if (!login.validate_email(email)&&login.validate_isnull(email)) {
					  $.jBox.tip("请输入正确的邮箱地址", "error");
					  //alert("请输入正确的邮箱地址!");
					   $(this).addClass("error")
				  }
			})
			login.changeComment=setInterval(function(){
				login.changeComments()
					
			},7000)
			$.each($(".inner_slider"),function(key,items){
				$(items).mousemove(function(){
					clearInterval(login.changeComment);
				})
				$(items).mouseout(function(){
				  login.changeComment=setInterval(function(){
						login.changeComments()
			     },7000)
				
				})
				
			})
			//成功案例
			$(".turn_back").click(function(){
				$(".succmove").animate({left:"-980px"},1200,"easeOutBack2",function(){
					$(".turn_brfore").fadeIn("slow");
					$(".turn_back").css({display:"none"})
				})
				//alert("dfs");
			})
			$(".turn_brfore").click(function(){
				$(".succmove").animate({left:"0px"},1200,"easeOutBack2",function(){
					$(".turn_back").fadeIn("slow");
					$(".turn_brfore").css({display:"none"});
					
				});
			})
			/*$.each($(".bg_cir li"),function(key,items){
				$(items).mousemove(function(){
					clearInterval(login.changeComment);
					$(".inner_slider").css({opacity:0.8});
					$(".inner_slider").removeClass("hd_current");
				    $(".inner_slider").eq(key).addClass("hd_current");
					$(".inner_slider").eq(key).animate({opacity:"1"},300)
				   $(".bg_cir li.bg_current").removeClass("bg_current");
				   $(".bg_cir li").eq(key).addClass("bg_current");
				})
				$(items).mouseout(function(){
					 login.changeComment=setInterval(function(){
						login.changeComments()
			       },2500)
					
				})
			
			})*/
			
		
       /* $("#extra a").hover(function(){
            $(this).stop(true, true).animate({
                opacity: 1
            }, 300)
            $("#icon_" + $(this).find("span").text()).stop(true, true).fadeIn(300)
			
        }, function(){
            $(this).stop(true, true).animate({
                opacity: 0.4
            }, 300)
            $("#icon_" + $(this).find("span").text()).stop(true, true).fadeOut(300)
        }).css({
            opacity: 0.4
        })*/
        $("#loginnav li").hover(function(ae){
            var e = window.event || ae;
            var s = e.fromElement || e.relatedTarget;
            if (document.all) {
                if (!(s == this || this.contains(s))) {
                    $(".navline").stop(true, false).animate({
                        left: $(this).attr("tag")
                    }, 300, "easeOutBack")
                }
            }
            else {
                var res = this.compareDocumentPosition(s);
                if (!(s == this || res == 20 || res == 0)) {
                    $(".navline").stop(true, false).animate({
                        left: $(this).attr("tag")
                    }, 300, "easeOutBack")
                }
            }
            
        }, function(ae){
            $(".navline").stop(true, false).animate({
                left: $(".navline").attr("tag")
            }, 500, "easeOutBack")
        }).click(function(){
			if($(this).attr("index")==2){
				clearInterval(login.changepic);
				login.changepic=setInterval(function(){
							login.changeimgs();
							},6200);
			}else{clearInterval(login.changepic);}
            if ($(this).attr("index") == 1) {
					  $("#extra").stop(true, true).animate({
						  height: "60px",
						  opacity: "show"
					  }, 500, "easeOutBounce")					
            }
            else {
                $("#extra").stop(true, true).animate({
                    height: "0px",
                    opacity: "hide"
                }, 500, "easeOutBounce")
            }
            $("#bdbg").stop(true, false).animate({
                left: 0 - 170 * $(this).attr("index")
            }, 1200, "easeOutBack2")
            $(".bdmain").stop(true, false).animate({
                left: 0 - 980 * $(this).attr("index")
            }, 1200, "easeOutBack2")
            $(".navline").attr("tag", $(this).attr("tag"))
        })
        $("#logBtn").click(function(){//登录
            login.sublogin();
           // login.saveUserInfo();
        })
		$(".authcode").click(function(){
			$("#authcodeImg").attr("src",Core.rootprefix+"/verificationcode?action=verificationCode&r="+Math.random());
			})
    },
	registered:function(){
			var ele=$("#loginnav li:eq(4)")
			$(".navline").stop(true, false).animate({left: ele.attr("tag")}, 300, "easeOutBack");
			$("#bdbg").stop(true, false).animate({left: 0 - 170 * ele.attr("index")}, 1200, "easeOutBack2")
            $(".bdmain").stop(true, false).animate({left: 0 - 980 * ele.attr("index")}, 1200, "easeOutBack2")
           	$(".navline").attr("tag", ele.attr("tag"))
	},
	changeComments:function(){
			login.oldIndex=login.num;
			if(login.flags==0 && login.num<3){
					login.num++
				}else if(login.num==3 && login.flags==0){
					login.flags=1;
					login.num--;
				}else if(login.num>0 && login.flags==1){
					login.num--;	
				}else if(login.num==0 && login.flags==1){
					login.flags=0;
					login.num++;
					}
				var num=login.num;
				
				$(".inner_slider").eq(login.oldIndex).animate({opacity:"0.2"},1000,function(){
					$(".inner_slider").css({opacity:0.2});
					$(".inner_slider").removeClass("hd_current");
					$(".inner_slider").eq(num).addClass("hd_current");
					$(".inner_slider").eq(num).animate({opacity:"1"},1000);
					
					})
				
				/*$(".bg_cir li.bg_current").removeClass("bg_current");
				$(".bg_cir li").eq(num).addClass("bg_current");*/
				
		
	},
    saveUserInfo: function(){
        if ($("#repsw").prop("checked") == true) {
            var userName = $("#username").val();
            var passWord = $("#psw").val();
            $.cookie("repsw", "true", {
                expires: 7
            });
            $.cookie("userName", userName, {
                expires: 7
            });
            $.cookie("passWord", passWord, {
                expires: 7
            });
        }
        else {
            $.cookie("repsw", "false", {
                expires: -1
            });
            $.cookie("userName", '', {
                expires: -1
            });
            $.cookie("passWord", '', {
                expires: -1
            });
        }
        
    },
    getTheAuthCode: function(){
        $("#authcodeImg").attr("src", Core.rootprefix + "/verificationcode?action=verificationCode&r=" + Math.random());
    },
    validator: function(){
        var errorMessage = "";
        if ($("#username").val() == "") {
            $.jBox.tip("请输入用户名！", "error");
			//alert("请输入用户名！")
            $("#username").focus();
            return false;
        }
        if ($("#psw").val() == "") {
           $.jBox.tip("请输入密码！", "error");
			 //alert("请输入密码！")
            $("#psw").focus();
            return false;
        }
        
        if ($("#psw").val().length < 6 || $("#psw").val().length > 20) {
            $.jBox.tip("密码必须在6到20位！", "error");
			//alert("密码必须在6到20位！")
            $("#psw").focus();
            return false;
        }
        
        if ($("#yzm").val() == "") {
            $.jBox.tip("请输入验证码！", "error");
			//alert("请输入验证码！")
            $("#yzm").focus();
            return false;
        }
        if ($("#yzm").val().length != 4) {
            $.jBox.tip("请输入4位验证码！", "error");
			//alert("请输入4位验证码！")
            $("#yzm").focus();
            $("#yzm").val("");
            return false;
        }
        return true;
    },
    sublogin: function(){
    	login.logon();
        return ;
    },
    loginDiv: function(){
    	window.location.href = 'page/index.html';
    },
    logon: function(){
        var temp = $("#logBtn").val();
        //$("#logBtn").html('<span>登录中</span>');
        $("#logBtn").val("登录中")
        $("#logBtn").attr("disabled", "disabled");
		$("#logBtn").css({cursor:"no-drop"});
        $("#logBtn").addClass('waiting_lb');
        var tempObj = new Object();
        var params = {
            "loginName": $("#username").val(),
            "pwd": $("#psw").val()
        };
        tempObj.params = params;
        
        if($("#repsw").prop("checked") == true){
        	params.iscookie= "true";
        }
        var isSuccess = loginRpc.login(params);
        
        if(isSuccess){
        	  $("#yzm").val("");
				
              $("#logBtn").removeAttr("disabled");
				$("#logBtn").css({cursor:"pointer"});
              $("#logBtn").val(temp);
              login.loginDiv();
              
        }else{
        	$.jBox.tip('用户名或密码有误，重新登录！', "error");
        	$("#logBtn").removeAttr("disabled");
            $("#logBtn").val(temp);
        }
    },
    dealNum: function(){
        var NUM = []
        login.endNum = login.targetNum =parseInt(new Date().getTime()/10000)+500000000;
        NUM = login.targetNum.toString().split("")
        for (var i = 0; i < NUM.length; i++) {
            $('#yusuan ul').append('<li class="num' + NUM[i] + '"></li>')
            $('#yusuan ul li:last').data("tag", (0 - NUM[i] * 6 * 53))
        }
        $('#yusuan ul').css('width', NUM.length * 53)
        setInterval("login.temp()", 10000)
    },
    temp: function(){
        login.endNum += parseInt(1000 * Math.random())//取得当前值
		
        var add = login.endNum - login.targetNum
        var delay
        login.weiNum = add.toString().split("").length - 2
        for (var t = 0; t < 9; t++) {
            clearInterval(login.intervalArr[t])
            if (t > (7 - login.weiNum)) {
                delay = 8 - (t - (7 - login.weiNum))
            }
            else {
                delay = 20 + (7 - login.weiNum - t) * 30
            }
            login.intervalArr[t] = setInterval("login.changeNum(" + t + ")", delay)
        }
        clearInterval(login.interval)
        login.interval = setInterval("login.setNum()", 120)
    },
    setNum: function(){
        login.stop = false
        login.targetNum += Math.pow(10, login.weiNum)
        if (login.targetNum >= login.endNum) {
            clearInterval(login.interval)
            login.targetNum = login.endNum
            setTimeout(function(){
                login.stop = true
            }, 480)
        }
    },
    changeNum: function(index){
        var newPos = parseInt($('#yusuan li:eq(' + index + ')').data("tag"))//css("background-position").split(" ")[0].replace("px", ""))
        if (index <= (7 - login.weiNum)) {
            if (!(Math.floor(0 - (newPos / 53) / 6) == login.targetNum.toString().split("")[index])) {
                newPos -= 53
                newPos = newPos < -3127 ? 0 : newPos
                $('#yusuan li:eq(' + index + ')').css("background-position", newPos + "px 0px").data("tag", newPos)
            }
        }
        else {
            if (!login.stop) {
                newPos -= 53
                newPos = newPos < -3127 ? 0 : newPos
                $('#yusuan li:eq(' + index + ')').css("background-position", newPos + "px 0px").data("tag", newPos)
            }
            else {
                $('#yusuan li:eq(' + index + ')').css("background-position", 0 - login.targetNum.toString().split("")[index] * 6 * 53 + "px 0px").data("tag", 0 - login.targetNum.toString().split("")[index] * 6 * 53)
            }
        }
    },
	registrationBlure:function(){
		var email = $("#email").val();
		var paw = $("#pasw").val();
		var prepaw = $("#rpsw").val();
		var compname=$("#compname").val();
		var qq=$("#qq").val();
		var ph = $("#phone").val();
		var ways=$("#ways").val();
		
	},
	validate_email:function (str){
			var re = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			return re.test(str);
	},
	validate_int:function (str){
			var reg = /^\d+$/;
			return reg.test(str);
	},
	validate_phone:function(str){//电话验证
			var reg=/^\d+(\-\d+)?$/g
			return reg.test(str);
	},
	validate_isnull:function (str){
			if (str) 
				return true;
			else 
				return false;
	},
	Registration:function(){//注册函数
		var email = $("#email").val();
		var paw = $("#pasw").val();
		var prepaw = $("#rpsw").val();
		var compname=$("#compname").val();
		var qq=$("#qq").val();
		var ph = $("#phone").val().replace(/\s/g,"");
		var ways=$("#ways").val();
		if (!login.validate_isnull(email)) {
			$.jBox.tip("邮箱地址不能为空", "error");
			//alert("邮箱地址不能为空!")
			$("#email").focus();
			return false;
   		 }
		else 
			if (!login.validate_email(email)&&login.validate_isnull(email)) {
				$.jBox.tip("请输入正确的邮箱地址", "error");
				//alert("请输入正确的邮箱地址!");
				$("#email").val("");
				$("#email").focus();
				return false;
			}
		if (!login.validate_isnull(paw)) {
			$.jBox.tip("请输入密码!", "error");
			//alert("请输入密码!")
			$("#pasw").focus();
			return false;
		}
		if (paw.length < 6 || paw.length > 20) {
			$.jBox.tip("密码必须在6~20位之间", "error");
			$("#pasw").val("");
			$("#rpsw").val("");
			$("#pasw").focus();
			return false;
		}
		if (!login.validate_isnull(prepaw)) {
			$.jBox.tip("请输入确认密码！", "error");
			$("#rpsw").focus();
			return false;
		}
		if (paw != prepaw) {
			$.jBox.tip("密码和确认密码不一致", "error");
			$("#rpsw").val("");
			$("#rpsw").focus();
			return false;
		}
		if(!login.validate_isnull(compname)){
			$.jBox.tip("请输入公司名称", "error");
			$("#compname").focus();
			return false
			}
		if(!login.validate_isnull(qq)){
			$.jBox.tip("请输入qq号码", "error");
			$("#qq").focus();
			return false;
		}else if(!login.validate_int(qq)&&login.validate_isnull(qq)){
			$.jBox.tip("请输入正确的qq号码！", "error");
			$("#qq").val("");
			$("#qq").focus();
			return false;
			}
			
		if (!login.validate_isnull(ph)) {
			$.jBox.tip("请输入电话号码！", "error");
			$("#phone").focus();
			return false
		}
		else if (!login.validate_phone(ph)&&login.validate_isnull(ph)) {
				$.jBox.tip("请输入正确的电话号码！", "error");
				$("#phone").val("");
				$("#phone").focus();
				return false;
			}
		//alert(ways)
		if(ways=="请选择"){
			$.jBox.tip("请选择获知途径!", "error");
			return false
		}
		if($("#agreeck").prop("checked")==false){
			$.jBox.tip("请认真阅读使用条款！", "error");
			return false;
		}
		$.jBox.tip("您的申请已提交成功，我们会尽快核实您的信息，激活您的账号！","success");
		$("#email").val("");
		$("#pasw").val("");
		$("#rpsw").val("");
		$("#phone").val("");
		$("#qq").val("");
		$("#compname").val("");
		$("#ways").val("--请选择--");
		$("#agreeck").attr("checked",false);
		
	},
	forgetPassWord:function(){
		$.blockUI({
			message : $("#forgetpasswordMain"),
			css : {
				top : "50%",
				left : "50%",
				margin : "-115px 0 0 -180px",
				border : "0 none",
				background : "transparent",
				textAlign : "left",
				cursor : "default"
			},
			overlayCSS:{
				backgroundColor : '#000'
			}
		});
		$("#forg_email").val("");
		$("#forg_username").val("");
	}
}
$(function(e){
    login.init();
    //reset_userinfo();

})



